<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* 登录模块
*/
class Login extends CI_Controller
{
	function __construct(){
		parent::__construct();
    }
    function __call($func,$args){
    	redirect('index/main','refresh');
    }
    //登录首页
	public function index() {
		$admin_id = $this->session->userdata('admin_id');
		if(empty($admin_id)) {
			$this->load->view('public/login');
		}else{
			redirect('index/main','refresh');
		}
	}
	//判断登录
	function check_login(){
		if ( is_post() ){
			$account = $this->input->post('account', TRUE);
			$password = md5($this->input->post('password', TRUE));
			$where = "account='{$account}' AND password='$password'";
			$this->db->select("*")->from("admin")->where($where,NULL,FALSE)->limit(1);
			$query = $this->db->get();
			if ($query->num_rows() > 0){
				$row_admin = $query->row();
				$this->session->set_userdata('admin_id', $row_admin->id);
				$this->session->set_userdata('admin_name', $row_admin->account);
				ajax_return('','登录成功',1);
			}else{
				ajax_return('','用户名或者错误');
			}
		}else{
			ajax_return('','用户名或者错误');
		}
	}
}
